package org.rbac.serv;

import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

@Service
public class MenuServices extends CommonServices {

	@SuppressWarnings("unchecked")
	public String getSystemMenu(String systemName) throws Exception {
		JSONObject returnObj = new JSONObject();
		try {
			String sql = "SELECT a.id id,a.a_name text,a.a_parentid parentId,a.a_type a_type" +
					" FROM permission_action a" +
					" LEFT JOIN pub_const const ON a.a_system= CONCAT(const.id,'')" +
					" WHERE a_status != 0 AND a_type = 2 AND const.c_value = ?" +
					" ORDER BY a_parentid ASC,a_type desc,NVL(a_sort, 999999999) ASC";
			List<Map<String, Object>> list = (List<Map<String, Object>>) getDao().executeSQLQuery(sql, systemName);
			JSONArray array = new JSONArray();
			for (Object map : list) {
				array.put(map);
			}
			returnObj.put("flag", "1");
			returnObj.put("msg", "成功");
			returnObj.put("data", array);
		} catch (Exception e) {
			returnObj.put("flag", "0");
			returnObj.put("msg", "失败");
			e.printStackTrace();
		}
		return returnObj.toString();
	}

}
